#include<bits/stdc++.h>
using namespace std;

int n , m , l , k , t , ma, mb;
int d[100010] , v[100010] , a[100010] , s[100010] , ans[100010];

int main()
{
    freopen("detect.in" , "r" , stdin);
    freopen("detect.out" , "w" , stdout);
    scanf("%d" , &t);
    while(t--)
    {
        ma = 0;
        mb = 0;
        memset(ans , 0 , sizeof(ans));
        scanf("%d%d%d%d" , &n , &m , &l , &k);
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d%d" , &d[i] , &v[i] , &a[i]);
        }
        for(int i = 1; i <= m; i++)
        {
            scanf("%d" , &s[i]);
        }
        sort(s + 1 , s + m + 1);
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                if(s[j] < d[i])
                {
                    continue;
                }
                long long x = v[i] * v[i] + 2 * a[i] * (s[j] - d[i]);
                if(x > 1ll * k * k)
                {
                    ma++;
                    ans[j] = 1;
                    break;
                }
                if(x == 0)
                {
                    break;
                }
            }
        }
        for(int i = 1; i <= m; i++)
        {
            if(ans[i] == 0)
            {
                mb++;
            }
        }
        printf("%d %d\n" , ma , mb);
    }
    return 0;
}
